package org.hulk.job.run;

import org.apache.log4j.Logger;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationLoader {
	private static Logger LOG = Logger.getLogger(ApplicationLoader.class);

	// public static void main(String[] args) {
	//
	// }
	// Spring上下文
	private static AbstractApplicationContext context;

	/**
	 * 获取 spring ApplicationContext
	 * 
	 * @return Spring上下文
	 * @author xkfeng@iflytek.com
	 * @created 2014-3-23 下午10:51:42
	 * @lastModified
	 * @history
	 */
	public static AbstractApplicationContext getContext() {
		return context;
	}

	/**
	 * 初始化上下文
	 * 
	 * @return 初始结果
	 * @author xkfeng@iflytek.com
	 * @created 2014-3-23 下午10:52:15
	 * @lastModified
	 * @history
	 */
	public static boolean loadContext() {
		// 加载Spring.Context
		LOG.info("loading applicationContext...");
		try {
			// context = new ClassPathXmlApplicationContext(new
			// String[]{"spring/applicationContext.xml"});
			context = new ClassPathXmlApplicationContext(
					new String[] { "spring_core/applicationContext.xml" });
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
